////////////////////////////////////////////////////////////////////////////////
//(c) Intelliquip, Inc. 2001
////////////////////////////////////////////////////////////////////////////////
//$Log:
// 2    Version 10.0 (Current View)1.1         6/1/2011 2:03:58 PM    Scott
//      Frees     IDD 09911:  xSheets and IQX integration
// 1    Version 10.0 (Current View)1.0         5/19/2011 2:22:46 PM   Jeff
//      Heigl      
//$
//$NoKeywords$
////////////////////////////////////////////////////////////////////////////////
package com.intelliquip.hydraulicselection.control.web;

import com.intelliquip.compressor.search.CompressorSearchFacade;
import com.intelliquip.compressor.search.output.SearchDetails;
import com.intelliquip.compressor.search.output.SearchDetailsList;
import com.intelliquip.hydraulicselection.RejectStatus;

public class RedirectConfigForCompressor extends RedirectConfig {

	public RedirectConfigForCompressor(RedirectParams parameterObject) {
		super(parameterObject);
	}

	@Override
	protected void searchAndValidate() throws RedirectValidationException {
		SearchDetails primary = compressorSearch();

		validateCompressorSearchDetails(primary);
	}

	private void validateCompressorSearchDetails(SearchDetails primary) throws RedirectValidationException {
		if(primary == null || primary.getRejectStatus() == RejectStatus.FULL_REJECT) {
			String targetReject = targetPath + ScreenNames.COMPRESSOR_DATASHEET_URL;
			throw new RedirectValidationException(getFullRejectMessage(), targetReject);
		}
	}

	private SearchDetails compressorSearch() {
		SearchDetails primary = userPreferences.getCompressorUser().getPrimarySearchDetails();
		try {
			//run a search with the users latest conditions
			SearchDetailsList searchDetailsList = CompressorSearchFacade.datasheetSearchAndUpdateUserPrefs(userPreferences, null);
			primary = searchDetailsList.getPrimaryResult(userPreferences.getCompressorCOS());
		} catch(Exception ex) {
			ex.printStackTrace();
		}
		return primary;
	}

}
